// FWin32System.cpp (c) 2011 JV Software
//

#include "FWin32System_Local.h"

FWin32System		win32Local;
SYS_API FSystem		*sys = &win32Local;

FArray<FWin32Window *> windows;

/*
================
FWin32System::UnloadModule
================
*/
void FWin32System::UnloadModule( FModule *module ) {
	delete module;
}

/*
================
FWin32System::LoadModule
================
*/
FModule *FWin32System::LoadModule( FString path ) {
	FWin32Module *module = new FWin32Module();

	if(!module->Load( path )) {
		UnloadModule( module );
		return NULL;
	}

	return module;
}

/*
================
FWin32System::Shutdown
================
*/
void FWin32System::Shutdown( void ) {
	for(int i = 0; i < windows.size(); i++ ) {
		delete windows[i];
	}

	windows.clear();
}

/*
================
FWin32System::AllocWindow
================
*/
FWindow	*FWin32System::AllocWindow( void ) {
	windows.push_back( new FWin32Window() );
	return windows[windows.size() - 1];
}

/*
================
FWin32System::FatalError
================
*/
void FWin32System::FatalError( FString fmt, ... ) {
	int			len; 
	va_list		argptr;
	wchar_t     *msg = (wchar_t *)fmt.c_str();
	static wchar_t	bigBuffer[32000];

	va_start (argptr,msg);
		len = vswprintf (bigBuffer,sizeof(bigBuffer),msg,argptr);
	va_end (argptr);

#ifdef _DEBUG
	_asm {
		int 3h
	};
#endif

	MessageBox( NULL, bigBuffer, TEXT("FATAL ERROR"), 0 );
	exit( 0 );
}